﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;
namespace IFRS.DataAccess.DAL
{
    public class ROLEGROUP
    {
        public DataTable SEARCH_ALL(RoleGroupU rolegroup ,Paging paging, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@RoleGroupName", rolegroup.RoleGroupName.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsActive", rolegroup.IsActive.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_ROLEGROUP_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int RoleGroupID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupID", RoleGroupID));
                dt = Utility.StoredProcDataTable("SPR_ROLEGROUP_SEARCHBYID", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_ROLEGROUPMENU_BYID(int RoleGroupID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupID", RoleGroupID));
                dt = Utility.StoredProcDataTable("SPR_ROLEGROUPMENU_SEARCHBYID", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }
        
        public int INSERT(string RoleGroupName, bool AllBranch, bool IsActive, DateTime? CreatedDate, string CreatedBy, string CreatedCostCenter, string CreatedBranch, DateTime? UpdatedDate, string UpdatedBy, string UpdatedCostCenter, string UpdatedBranch)
        {

            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@RoleGroupName", RoleGroupName));
                lstParams.Add(new SqlParameter("@AllBranch", AllBranch));
                lstParams.Add(new SqlParameter("@IsActive", IsActive));
                lstParams.Add(new SqlParameter("@CreatedDate", CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", UpdatedBranch));


                Utility.ExecuteStoredProc("SPR_ROLEGROUP_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(int RoleGroupID, string RoleGroupName, bool AllBranch, bool IsActive, DateTime? CreatedDate, string CreatedBy, string CreatedCostCenter, string CreatedBranch, DateTime? UpdatedDate, string UpdatedBy, string UpdatedCostCenter, string UpdatedBranch)
        {


            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupID", RoleGroupID));
                lstParams.Add(new SqlParameter("@RoleGroupName", RoleGroupName));
                lstParams.Add(new SqlParameter("@AllBranch", AllBranch));
                lstParams.Add(new SqlParameter("@IsActive", IsActive));
                lstParams.Add(new SqlParameter("@CreatedDate", CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_ROLEGROUP_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE_ROLEGROUPMENU(int RoleGroupMenuID, bool IsUsed, bool IsView, bool IsAdd, bool IsEdit, bool IsDelete, bool IsPrint, DateTime? CreatedDate, string CreatedBy, string CreatedCostCenter, string CreatedBranch, DateTime? UpdatedDate, string UpdatedBy, string UpdatedCostCenter, string UpdatedBranch)
        {


            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupMenuID", RoleGroupMenuID));
                lstParams.Add(new SqlParameter("@IsUsed", IsUsed));
                lstParams.Add(new SqlParameter("@IsView", IsView));
                lstParams.Add(new SqlParameter("@IsAdd", IsAdd));
                lstParams.Add(new SqlParameter("@IsEdit", IsEdit));
                lstParams.Add(new SqlParameter("@IsDelete", IsDelete));
                lstParams.Add(new SqlParameter("@IsPrint", IsPrint));
                lstParams.Add(new SqlParameter("@CreatedDate", CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_ROLEGROUPMENU_UPDATE", lstParams.ToArray());


            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(RoleGroupU RoleGroup)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupID", RoleGroup.RoleGroupID));
                lstParams.Add(new SqlParameter("@UpdatedDate", RoleGroup.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", RoleGroup.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", RoleGroup.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", RoleGroup.UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_ROLEGROUP_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }


    }
}
